package com.mayinghao.stat.jfree;

import java.awt.*;
import javax.swing.*;

import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.*;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.*;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;


public class LineExample {
public LineExample() {
JFrame frame = new JFrame("Line Example");
Container content = frame.getContentPane();
content.setLayout(new FlowLayout());

final XYDataset dataset =createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

content.add(chartPanel);

frame.pack();
frame.setVisible(true);
}

private XYDataset createDataset() { 
final XYSeries series1 = new XYSeries("First");

for (int i = 1; i <= 53; i++) {
series1.add(i, Math.random() * 50);
}

final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);

return dataset;
}

private JFreeChart createChart(final XYDataset dataset) {

return new JFreeChart(new XYPlot(dataset, 
new NumberAxis("X"), 
new NumberAxis("Y"), 
new StandardXYItemRenderer()
));

}

public static void main(String[] args) {

new LineExample();

}
}